package com.fa.dv.service.impl;

import com.fa.common.utils.SecurityUtils;
import com.fa.dv.domain.Machinery;
import com.fa.dv.domain.Workshop;
import com.fa.dv.mapper.MachineryMapper;
import com.fa.dv.service.IMachineryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class MachineryServiceImpl implements IMachineryService {
    @Autowired
    private MachineryMapper machineryMapper;
    @Override
    public List<Machinery> list(Machinery machinery) {
        return machineryMapper.list(machinery);
    }

    @Override
    public List<Workshop> getWorkshop() {
        return machineryMapper.getWorkshop();
    }

    @Override
    public void insert(Machinery machinery) {
        machinery.setWorkshopName(getWorkshopName(machinery.getWorkshopId()));
        System.out.println("这是新增的WorkshopName"+machinery.getWorkshopName());
        machinery.setCreateBy(SecurityUtils.getUsername());
        machinery.setUpdateBy(SecurityUtils.getUsername());
        machinery.setCreateTime(new Date());
        machinery.setUpdateTime(new Date());
        machineryMapper.insert(machinery);
    }

    @Override
    public String getWorkshopName(Long workshopId) {
        return machineryMapper.getWorkshopName(workshopId);
    }

    @Override
    public Machinery getMachineryTypeNameById(Long machineryId) {
        return machineryMapper.getMachineryTypeNameById(machineryId);
    }

    @Override
    public void update(Machinery machinery) {
        machinery.setUpdateBy(SecurityUtils.getUsername());
        machinery.setUpdateTime(new Date());
        machineryMapper.update(machinery);
    }

    @Override
    public void delete(Long machineryId) {
        machineryMapper.delete(machineryId);
    }

    @Override
    public void saveBatch(ArrayList<Machinery> cacheList) {
        machineryMapper.insertBatch(cacheList);
    }
}
